import {Injectable} from "@angular/core";
import { HttpClient,HttpParams } from '@angular/common/http';

@Injectable()
export class RollService {
  serveUrl='http://clientaccountserver.lessonplan.cn'; /*学生用户服务器*/
  classServeurl='http://rosterserver.lessonplan.cn'; /*花名册服务器*/
  constructor(
    private http: HttpClient,
  ) { }
  /*根据学生的guid获取学生加入的班级的Guid*/
 getJoinClass (stuGuid):Promise<any> {
     return this.http.get(this.serveUrl+'/user/joined/'+stuGuid).toPromise().then(res=>{
        return res;
    })
 }
  /*根据班级Guid列表查询所有的班级*/
 getClassList(classGuidList):Promise<any> {
   return this.http.get(this.classServeurl+'/class/private',{
     params: new HttpParams().set('classListString',classGuidList)}).toPromise().then(res=>{
       return res;
   })
 }
  /*对输入关键字进行查询*/
 getSearchClassList(searchText:string,stuGuid:string):Promise<any>{
     return this.http.get(this.classServeurl+'/class/search',{
       params: new HttpParams().set('searchText',searchText).set('FK_UserGuid',stuGuid)}).toPromise().then(res=>{
         return res;
     })
 }
  /*加入班级*/
 joinClass(data:object):Promise<any>{
   return this.http.post(this.classServeurl+'/class/join',data).toPromise().then(res=>{
     return res ;
   })
 }
 /*根据班级guid和学生guid获取通知列表,state:0正常通知，99被删除的通知*/
 getNoticeList(classGuid,stuGuid):Promise<any>{
   return this.http.get(this.classServeurl+'/notice/getNoticeByUser',{
     params:new HttpParams().set('FK_ClassGuid',classGuid).set('FK_UserGuid',stuGuid)
   }).toPromise().then(res=>{
     return res;
   })
 }
 /*学生读取通知*/
 postReadNotice(data:object):Promise<any>{
   return this.http.post(this.classServeurl+'/notice/read',data).toPromise().then(res=>{
     return res;
   })
 }
 /*学生是否有未读的通知*/
 getUnread(classGuid,stuGuid):Promise<any>{
   return this.http.get(this.classServeurl+'/notice/Unread',{
     params:new HttpParams().set('FK_ClassGuid',classGuid).set('FK_UserGuid',stuGuid)
   }).toPromise().then(res=>{
     return res;
   })
 }
 /*根据班级Guid获取学生列表*/
  getStudentlist(classGuid:string):Promise<any>{
    return this.http.get(this.serveUrl+'/user/studentlist/'+classGuid).toPromise().then(res=>{
      return res;
    })
  }
  /*根据班级GUID和学生GUID获取学生成绩 扫码成绩*/
  getScoreOfStudent(classGuid,stuGuid):Promise<any>{
    let data = {
      studentGuid:stuGuid,
      classGuid:classGuid
    };
    return this.http.post('http://qrcodeserver.lessonplan.cn/score/detail',data).toPromise().then(res=>{
      return res;
    })
  }
  /*根据班级Guid获取成绩计算模型*/
  getScoreCountModle(classGuid):Promise<any>{
    return this.http.get(this.classServeurl+'/scoresegment/list/'+classGuid).toPromise().then(res=>{
      return res;
    })
  }
  /*获取作业墙的成绩*/
  getScoreOfHomework(classGuid,stuGuid):Promise<any>{
    return this.http.get('http://homeworkserver.lessonplan.cn/teamMember/userScoreByClass',{
      params:new HttpParams().set('UserGuid',stuGuid).set('FK_ClassGuid',classGuid)
    }).toPromise().then(res=>{
      return res;
    })
  }
}



